<template>
  <el-dialog v-if="popenevTVisible" :title="modalTitle" :before-close="handleCancel" :visible.sync="popenevTVisible" width="420px" :close-on-click-modal="false">
    <div class="message-tip" v-html="modalText"></div>
    <span slot="footer" class="dialog-footer">

      <el-button v-if="showBtnRight" @click="handleCancel">取消</el-button>
      <el-button v-for="(btn, index) in btnList" :key="index" type="primary" @click="handleOk(btn)">{{ btn.btnTitle }}</el-button>
      <el-button v-if="!showBtnRight" @click="handleCancel">取消</el-button>
    </span>
  </el-dialog>
</template>

<script>
import { clickEvent } from "../../event/eventClick";
export default {
  name: "messageboxEvent",
  data() {
    return {
      popenevTVisible: true,
      btnList: [],
      showBtnRight: window.HC_config.VUE_APP_SHOWTOPICON,
      modalText: null,
      modalTitle: null,
      promiseStatus: null,
      otherObj: {},
      record: null,
    };
  },
  methods: {
    show(btnList, modalText, record, otherObj, config) {
      this.btnList = btnList || [];
      console.log(this.btnList);
      this.modalText = modalText || "";
      this.modalTitle = config.modalTitle || "询问";
      this.otherObj = otherObj || {};
      this.record = record || null;
      // 创建promise
      return new Promise((resolve, reject) => {
        this.promiseStatus = {
          resolve,
          reject,
        };
      });
    },
    handleCancel() {
      this.promiseStatus.reject();
      this.destroyElement();
    },
    handleOk(cEvent) {
      clickEvent({ btnEvent: cEvent }, this.record, this.otherObj);
      this.promiseStatus.resolve();
      this.destroyElement();
    },
    /**
     * cs 2022-4-8
     * 销毁组件
     */
    destroyElement() {
      this.popenevTVisible = false;
      // this.$destroy(true);
    },
  },
};
</script>

<style lang="scss" scoped>
::v-deep .el-dialog {
  border-radius: 10px;
}

::v-deep .el-dialog__body {
  padding: 10px;
  text-align: center;
}

.message-tip {
  font-size: 14px;
  line-height: 24px;
}
</style>